using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter09
{
	/// <summary>
	/// Example11: Proton- Proton Collision
	/// A proton collides elastically with anther proton that 
	/// is initially at rest. The incoming proton has an initial 
	/// speed of 3.50 \times 10^5 m/s and makes a glancing collision with 
	/// the second proton, as in Figure 9.13 
	/// (At close separation, the protons exert a repulsive 
	/// electrostatic force on each other.) 
	/// After the collision, one proton moves off at an angle 
	/// of 37.0^{\circle} to the original direction of motion, 
	/// and the second deflects at an angle of \phi^{\circle} 
	/// to the same axis. Find the final speeds of the two 
	/// protons and the angle \phi.
	/// v_1f = 2.8 \times 10^5 m/s
	/// \phi = 53.0^{\circle}
	/// </summary>
	public class Example11
	{
		public Example11()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			// use the relation of perpendicular
			L.Vector v1 = new L.Vector();
			v1.X = 3.5*100000.0;
			L.Vector v2 = new L.Vector();
			L.Vector v3;
			double min = 10000000.0;
			double tempv = 0.0; 
			double v3x = 0.0, v3y = 0.0;
			for(int i = 1000; i < 1000000; i++)
			{
				
				double v = 279522.0+0.00001*(double) i;
				v2.X = v*Math.Cos(37.0*Math.PI/180.0);
				v2.Y = v*Math.Sin(37.0*Math.PI/180.0);
				v3 = v1 - v2;
				if(Math.Abs((v2*v3).Magnitude) < min)
				{
					min = Math.Abs((v2*v3).Magnitude);
					tempv = v;
					v3x = v3.X;
					v3y = v3.Y;
				}
			}
			result+=Convert.ToString(min)+"\r\n";
			result+=Convert.ToString(tempv)+"\r\n";
			result+=Convert.ToString(Math.Atan(v3y/v3x)
				*180.0/Math.PI)+"\r\n";
		}
	}
}
